package ThreadDemo3;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:内存可见性
 * User: 阿宾
 * Date: 2025-03-26
 * Time:
 */
public class ThreadDemo5 {
    private volatile static int flag = 0;
    public static void main(String[] args) throws InterruptedException {
        //创建两个线程
        Thread t1 = new Thread(()->{
            while (flag == 0){

            }
            System.out.println("t1线程执行完毕");
        });

        Thread t2 = new Thread(()->{
            System.out.println("请输入flag的值");
            Scanner scanner = new Scanner(System.in);
            flag = scanner.nextInt();

        });
        t1.start();
        t2.start();
    }
}